var queryParam = null;
$(function(){
    var id = $("#exampleId").val();
    queryParam = {"example_id" : id};
    getListPage();
});

function getListPage(param){
    param = $.extend(queryParam,param);
    $.ajax({
        type : "post",
        url : "htmlWeb/getRecommendUserList",
        data: param,
        async: false,
        success : function(data){
            $("#caseRecommendPageHead ~ tr").remove();
            var str = "";
            var cnName = "",workName = "";

            $.each(data.rows,function(i,obj){
                obj = trimEmpty(obj);
                if(obj.recommendUser){
                    cnName = obj.recommendUser.cnName;
                    if(obj.recommendUser.bizWork){
                        workName = obj.recommendUser.bizWork.name;
                    }
                }
                str += '<tr><td><p>' + obj.id + '</p></td>' +
                    '<td><span>' + cnName + '</span></td>' +
                    '<td><span>' + workName + '</span></td>' +
                    '<td><span>' + obj.sort + '</span></td>' +
                    '<td><span class="userSpan"><a class="cur" href="javascript:void(0);" onclick="editRecommend('+ obj.id + ')">编辑</a>' +
                    '<a class="cur" href="javascript:void(0);" onclick="deleteRecommend('+ obj.id + ')">删除</a></span></td></tr>';
            });
            $("#caseRecommendPageHead").after(str);
            createPage(data);

        },
        error : function(data){
            console.log(data);
        }
    });
}

function editRecommend(id) {
    var jsPath = "../../by-webhtml/assets/js/system/system_recommendAdd.js";
    $(".mainDiv").load("/htmlWeb/systemRecommendAddHtml", '', function () {
        $("#exampleId_update").val(queryParam.example_id);
        $("#exampleRecommendId_update").val(id);
        $.getScript(jsPath);
    });
}

function deleteRecommend(id) {
    $.post("htmlWeb/deleteRecommendUser",{"id" : id},function(data){
        tip("删除推荐成功");
        goPage(1);
    });
}